<!DOCTYPE html>
<html lang=zh>
<head><meta name="generator" content="Hexo 3.9.0">
    <!-- so meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="HandheldFriendly" content="True">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="description" content="前言不知道大家在 windows 下有没有遇到这种错误？明明包装得好好的说什么没有设置 python 环境变量，然后我到环境变量设置界面一看，python 变量都设置了呀，在 cmd 中echo PATH也能看到设置的 python 的环境变量。 Node gpy node-gyp is a cross-platform command-line tool written in Node.js f">
<meta name="keywords" content="nodejs">
<meta property="og:type" content="article">
<meta property="og:title" content="node gpy 报错">
<meta property="og:url" content="https://andyliwr.github.io/2018/04/24/node_gpy_install_fail/index.html">
<meta property="og:site_name" content="月光倾城的代码小屋">
<meta property="og:description" content="前言不知道大家在 windows 下有没有遇到这种错误？明明包装得好好的说什么没有设置 python 环境变量，然后我到环境变量设置界面一看，python 变量都设置了呀，在 cmd 中echo PATH也能看到设置的 python 的环境变量。 Node gpy node-gyp is a cross-platform command-line tool written in Node.js f">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://file.lantingshucheng.com/1524540596938.png/800x400">
<meta property="og:image" content="https://file.lantingshucheng.com/1524544026718.png/800x400">
<meta property="og:image" content="https://file.lantingshucheng.com/1524545060774.png">
<meta property="og:updated_time" content="2020-01-15T06:30:09.120Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="node gpy 报错">
<meta name="twitter:description" content="前言不知道大家在 windows 下有没有遇到这种错误？明明包装得好好的说什么没有设置 python 环境变量，然后我到环境变量设置界面一看，python 变量都设置了呀，在 cmd 中echo PATH也能看到设置的 python 的环境变量。 Node gpy node-gyp is a cross-platform command-line tool written in Node.js f">
<meta name="twitter:image" content="https://file.lantingshucheng.com/1524540596938.png/800x400">
    
    
        
          
              <link rel="shortcut icon" href="/images/favicon.ico">
          
        
        
          
            <link rel="icon" type="image/png" href="/images/favicon-192x192.png" sizes="192x192">
          
        
        
          
            <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
          
        
    
    <!-- title -->
    <title>node gpy 报错</title>
    <!-- styles -->
    <link rel="stylesheet" href="/css/style.css">
    <!-- persian styles -->
    
      <link rel="stylesheet" href="/css/rtl.css">
    
    <!-- rss -->
    
    
</head>

<body class="max-width mx-auto px3 ltr">
    
      <div id="header-post">
  <a id="menu-icon" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="menu-icon-tablet" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="top-icon-tablet" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');" style="display:none;"><i class="fas fa-chevron-up fa-lg"></i></a>
  <span id="menu">
    <span id="nav">
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/others/">其他文章</a></li>
        
      </ul>
    </span>
    <br/>
    <span id="actions">
      <ul>
        
        <li><a class="icon" href="/2018/04/28/travis_node_publish2/"><i class="fas fa-chevron-left" aria-hidden="true" onmouseover="$('#i-prev').toggle();" onmouseout="$('#i-prev').toggle();"></i></a></li>
        
        
        <li><a class="icon" href="/2018/04/23/node_canvas_usage/"><i class="fas fa-chevron-right" aria-hidden="true" onmouseover="$('#i-next').toggle();" onmouseout="$('#i-next').toggle();"></i></a></li>
        
        <li><a class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up" aria-hidden="true" onmouseover="$('#i-top').toggle();" onmouseout="$('#i-top').toggle();"></i></a></li>
        <li><a class="icon" href="#"><i class="fas fa-share-alt" aria-hidden="true" onmouseover="$('#i-share').toggle();" onmouseout="$('#i-share').toggle();" onclick="$('#share').toggle();return false;"></i></a></li>
      </ul>
      <span id="i-prev" class="info" style="display:none;">上一篇</span>
      <span id="i-next" class="info" style="display:none;">下一篇</span>
      <span id="i-top" class="info" style="display:none;">返回顶部</span>
      <span id="i-share" class="info" style="display:none;">分享文章</span>
    </span>
    <br/>
    <div id="share" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=https://andyliwr.github.io/2018/04/24/node_gpy_install_fail/"><i class="fab fa-facebook " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=https://andyliwr.github.io/2018/04/24/node_gpy_install_fail/&text=node gpy 报错"><i class="fab fa-twitter " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=https://andyliwr.github.io/2018/04/24/node_gpy_install_fail/&title=node gpy 报错"><i class="fab fa-linkedin " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=https://andyliwr.github.io/2018/04/24/node_gpy_install_fail/&is_video=false&description=node gpy 报错"><i class="fab fa-pinterest " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=node gpy 报错&body=Check out this article: https://andyliwr.github.io/2018/04/24/node_gpy_install_fail/"><i class="fas fa-envelope " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=https://andyliwr.github.io/2018/04/24/node_gpy_install_fail/&title=node gpy 报错"><i class="fab fa-get-pocket " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=https://andyliwr.github.io/2018/04/24/node_gpy_install_fail/&title=node gpy 报错"><i class="fab fa-reddit " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=https://andyliwr.github.io/2018/04/24/node_gpy_install_fail/&title=node gpy 报错"><i class="fab fa-stumbleupon " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=https://andyliwr.github.io/2018/04/24/node_gpy_install_fail/&title=node gpy 报错"><i class="fab fa-digg " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=https://andyliwr.github.io/2018/04/24/node_gpy_install_fail/&name=node gpy 报错&description="><i class="fab fa-tumblr " aria-hidden="true"></i></a></li>
</ul>

    </div>
    <div id="toc">
      <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#前言"><span class="toc-number">1.</span> <span class="toc-text">前言</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Node-gpy"><span class="toc-number">2.</span> <span class="toc-text">Node gpy</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#解决方法"><span class="toc-number">3.</span> <span class="toc-text">解决方法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#重新安装-Python"><span class="toc-number">3.1.</span> <span class="toc-text">重新安装 Python</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Python-版本问题"><span class="toc-number">3.2.</span> <span class="toc-text">Python 版本问题</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#参考文档"><span class="toc-number">4.</span> <span class="toc-text">参考文档</span></a></li></ol>
    </div>
  </span>
</div>

    
    <div class="content index py4">
        
        <article class="post" itemscope itemtype="http://schema.org/BlogPosting">
  <header>
    
    <h1 class="posttitle" itemprop="name headline">
        node gpy 报错
    </h1>



    <div class="meta">
      <span class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">
        <span itemprop="name">月光倾城的代码小屋</span>
      </span>
      
    <div class="postdate">
        <time datetime="2018-04-24T11:25:49.000Z" itemprop="datePublished">2018-04-24</time>
    </div>


      

      
    <div class="article-tag">
        <i class="fas fa-tag"></i>
        <a class="tag-link" href="/tags/nodejs/">nodejs</a>
    </div>


    </div>
  </header>
  

  <div class="content" itemprop="articleBody">
    <h3 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h3><p>不知道大家在 windows 下有没有遇到这种错误？明明包装得好好的说什么没有设置 python 环境变量，然后我到环境变量设置界面一看，python 变量都设置了呀，在 cmd 中<code>echo PATH</code>也能看到设置的 python 的环境变量。<br><img src="https://file.lantingshucheng.com/1524540596938.png/800x400" alt="npm 错误"><br><img src="https://file.lantingshucheng.com/1524544026718.png/800x400" alt="系统环境变量"></p>
<h3 id="Node-gpy"><a href="#Node-gpy" class="headerlink" title="Node gpy"></a>Node gpy</h3><blockquote>
<p><code>node-gyp</code> is a cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js. It bundles the gyp project used by the Chromium team and takes away the pain of dealing with the various differences in build platforms. It is the replacement to the node-waf program which is removed for node v0.8. If you have a native addon for node that still has a wscript file, then you should definitely add a binding.gyp file to support the latest versions of node.</p>
</blockquote>
<p><code>gyp</code>其实是一个用来生成项目文件的工具，一开始是设计给<code>chromium</code>项目使用的，后来大家发现比较好用就用到了其他地方。生成项目文件后就可以调用<code>GCC</code>, <code>vsbuild</code>, <code>xcode</code>等编译平台来编译。至于为什么要有<code>node-gyp</code>，是由于<code>node</code>程序中需要调用一些其他语言编写的工具甚至是<code>dll</code>，需要先编译一下，否则就会有跨平台的问题，例如在<code>windows</code>上运行的软件 copy 到 mac 上就不能用了，但是如果源码支持，编译一下，在<code>mac</code>上还是可以用的。</p>
<h3 id="解决方法"><a href="#解决方法" class="headerlink" title="解决方法"></a>解决方法</h3><p>linux 一直都是二进制分发，npm 为了方便干脆就直接源码分发，用户装的时候再现场编译。再看看错误输出，大致意思就是 node-gpy 需要使用到 python 去编译某个东西。但是在路径中又找不到可执行的 python 程序。</p>
<h4 id="重新安装-Python"><a href="#重新安装-Python" class="headerlink" title="重新安装 Python"></a>重新安装 Python</h4><p>方法一：卸载 python，重新到<a href="https://www.python.org/downloads/windows/" target="_blank" rel="noopener">官网</a>下载一份安装，安装的时候记得勾选“添加 Python 至环境变量”</p>
<p>安装好了之后再试试<code>npm install</code></p>
<h4 id="Python-版本问题"><a href="#Python-版本问题" class="headerlink" title="Python 版本问题"></a>Python 版本问题</h4><p>上面的方法试了之后还是不行的话，可能是 python 的版本引起的，试着换成 python2.7，或者运行下面的命令来安装默认版本：</p>
<figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install --global --production windows-build-tools</span><br></pre></td></tr></table></figure>
<p>记得上述命令需要在 cmd(管理员)的环境中执行。</p>
<p><img src="https://file.lantingshucheng.com/1524545060774.png" alt="cmd"></p>
<h3 id="参考文档"><a href="#参考文档" class="headerlink" title="参考文档"></a>参考文档</h3><ul>
<li><a href="https://blog.csdn.net/weixin_36222137/article/details/78463543" target="_blank" rel="noopener">Error: Can’t find Python executable “python”, you can set the PYTHON env variable.解决办法</a></li>
<li><a href="https://github.com/nodejs/node-gyp" target="_blank" rel="noopener">node-gpy</a></li>
</ul>

  </div>
  <div class="statement">
    <hr>  
    1. 如果本文帮到了您，不妨点一下右上角的”<i class="fas fa-share-alt"></i>“按钮。<br>
    2. 除非注明，本博文章均为原创，转载请以链接形式标明本文地址。<br>
    3. 如果你有任何疑问，欢迎发送邮件到我的邮箱<a href="mailto:andyliwr@outlook.com">andyliwr@outlook.com<br>
  </div>
</article>


    <div class="blog-post-comments">
        <div id="gitalk_thread">
            <noscript>加载评论需要在浏览器启用 JavaScript 脚本支持。</noscript>
        </div>
    </div>



        
          <div id="footer-post-container">
  <div id="footer-post">

    <div id="nav-footer" style="display: none">
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/others/">其他文章</a></li>
        
      </ul>
    </div>

    <div id="toc-footer" style="display: none">
      <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#前言"><span class="toc-number">1.</span> <span class="toc-text">前言</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Node-gpy"><span class="toc-number">2.</span> <span class="toc-text">Node gpy</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#解决方法"><span class="toc-number">3.</span> <span class="toc-text">解决方法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#重新安装-Python"><span class="toc-number">3.1.</span> <span class="toc-text">重新安装 Python</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Python-版本问题"><span class="toc-number">3.2.</span> <span class="toc-text">Python 版本问题</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#参考文档"><span class="toc-number">4.</span> <span class="toc-text">参考文档</span></a></li></ol>
    </div>

    <div id="share-footer" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=https://andyliwr.github.io/2018/04/24/node_gpy_install_fail/"><i class="fab fa-facebook fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=https://andyliwr.github.io/2018/04/24/node_gpy_install_fail/&text=node gpy 报错"><i class="fab fa-twitter fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=https://andyliwr.github.io/2018/04/24/node_gpy_install_fail/&title=node gpy 报错"><i class="fab fa-linkedin fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=https://andyliwr.github.io/2018/04/24/node_gpy_install_fail/&is_video=false&description=node gpy 报错"><i class="fab fa-pinterest fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=node gpy 报错&body=Check out this article: https://andyliwr.github.io/2018/04/24/node_gpy_install_fail/"><i class="fas fa-envelope fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=https://andyliwr.github.io/2018/04/24/node_gpy_install_fail/&title=node gpy 报错"><i class="fab fa-get-pocket fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=https://andyliwr.github.io/2018/04/24/node_gpy_install_fail/&title=node gpy 报错"><i class="fab fa-reddit fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=https://andyliwr.github.io/2018/04/24/node_gpy_install_fail/&title=node gpy 报错"><i class="fab fa-stumbleupon fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=https://andyliwr.github.io/2018/04/24/node_gpy_install_fail/&title=node gpy 报错"><i class="fab fa-digg fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=https://andyliwr.github.io/2018/04/24/node_gpy_install_fail/&name=node gpy 报错&description="><i class="fab fa-tumblr fa-lg" aria-hidden="true"></i></a></li>
</ul>

    </div>

    <div id="actions-footer">
        <a id="menu" class="icon" href="#" onclick="$('#nav-footer').toggle();return false;"><i class="fas fa-bars fa-lg" aria-hidden="true"></i> 菜单</a>
        <a id="toc" class="icon" href="#" onclick="$('#toc-footer').toggle();return false;"><i class="fas fa-list fa-lg" aria-hidden="true"></i> 目录</a>
        <a id="share" class="icon" href="#" onclick="$('#share-footer').toggle();return false;"><i class="fas fa-share-alt fa-lg" aria-hidden="true"></i> 分享</a>
        <a id="top" style="display:none" class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up fa-lg" aria-hidden="true"></i> 返回顶部</a>
    </div>

  </div>
</div>

        
        <footer id="footer">
  <div class="footer-left">
    Copyright &copy; 2020 Dikang Li
  </div>
  <div class="footer-right">
    <nav>
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/others/">其他文章</a></li>
        
      </ul>
    </nav>
  </div>
</footer>

    </div>
</body>
</html>
<!-- styles -->
<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
<link rel="stylesheet" href="/lib/justified-gallery/css/justifiedGallery.min.css">
<link rel="stylesheet" href="/lib/fancybox/jquery.fancybox.css">

<link rel="stylesheet" href="https://file.lantingshucheng.com/blog/v3/static/styles/gitalk.css">


<!-- jquery -->
<script src="/lib/jquery/jquery.min.js"></script>
<script src="/lib/justified-gallery/js/jquery.justifiedGallery.min.js"></script>
<script src="/lib/fancybox/jquery.fancybox.pack.js"></script>

<script type="text/javascript" src="https://file.lantingshucheng.com/blog/v3/static/scripts/md5.js"></script>
<script type="text/javascript" src="https://file.lantingshucheng.com/blog/v3/static/scripts/gitalk.min.js"></script>

<script src="/js/main.js"></script>
<!-- search -->

<!-- Google Analytics -->

<!-- Baidu Analytics -->

    <script type="text/javascript">
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?7851ca7a86be957be994acb77639a5be";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>

<!-- Disqus Comments -->


  <script type="text/javascript">
    window.onload = function(){
      if (window.location.href.indexOf('andyliwr.github.io') > -1) {
        var gitalk = new Gitalk({
          clientID: 'ad6f70df0c70d2b715f9',
          clientSecret: '40384bee244c1e17dd7c37733d21e9ef669e969c',
          repo: 'Andyliwr.github.io',
          owner: 'Andyliwr',
          admin: ['Andyliwr'],
          id: md5(location.pathname),
          distractionFreeMode: 'true'
        })
        gitalk.render('gitalk_thread')
      }
    }
  </script>


